home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-08-26 | 54.2 KB | 1,580 lines |
- /********************************************************/
- /* Stars Module for SkyView */
- /* */
- /* (c)1992 N P Hawkes */
- /* */
- /* Displays the stars in the file 'StarData'. Stars are */
- /* identified by Flamsteed & Bayer names, constellation */
- /* name, B S catalogue number and proper name if any. */
- /********************************************************/
-
- #include "menu.h"
- #include "bbc.h"
- #include "wimpt.h"
- #include "dbox.h"
- #include "event.h"
- #include "res.h"
- #include "resspr.h"
- #include "sprite.h"
- #include "werr.h"
-
- #include "sv_header.h"
- #include "stars.h"
- #include "radec.h"
-
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- /********************************************************/
- /* Constants */
- /********************************************************/
-
- #define FILE_NAME "StarData" /* Name of data file. */
- #define DEF_FILE "StarDefs" /* File of Disp. defaults*/
- #define DISP_NAME ">Stars " /* Entry in Display menu.*/
- #define SEL_NAME " Star " /* Entry in Select menu. */
-
- #define HORALT (REAL)0.0044 /* Altitude of horizon. */
-
- #define MAX_STARS 600 /* Max no. of stars. */
- #define NUMGRPS 8 /* No. of magnitude groups. */
- #define NUMSPRITES 21 /* No. of different star symbols*/
- #define SPRNAM_MAX 13 /* Max len of a spr name, plus 1*/
-
- /* Name of Display dialogue box (for changing sprites): */
- #define DISP_BOX "StarDisp"
-
- /* Define characteristics of sprites. */
- #define SPR_X0 -12 /* Bounding box of */
- #define SPR_Y0 -12 /* sprite, OS units, */
- #define SPR_X1 14 /* relative to */
- #define SPR_Y1 14 /* plotting position. */
- #define SPR_COL 5 /* Sprite x offset. */
- #define SPR_ROW 4 /* Sprite y offset. */
- #define SPR_MODE MODE_20 /* Sprite mode. */
-
- /* Field lengths in data file. */
- #define FLAMST_LEN 4 /* Field len for Flamsteed id. */
- #define BAYER_LEN 9 /* Length of Bayer string. */
- #define CONSTELLEN 3 /* Field len for constell. abbrev.*/
- #define MAX_PROPER 30 /* Max len of proper name. */
-
- /* Field lengths in Select dialogue boxes. */
- /* Must be large enough for longest item. */
- #define MAX_FIELD 30
-
- /* Number of methods of selecting a star: */
- #define SEL_METHODS 4
-
- /* Constants identifying method of selection: */
- enum {
- by_proper = 1,
- by_bayer,
- by_flamst,
- by_catlg
- };
-
- /* Items for Select sub-menu. */
- #define STARSEL_SUB_NAME "Select Star:"
- #define STARSEL_SUB_ITEMS "\
- By proper name, \
- By Bayer letter, \
- By Flamsteed No., \
- By BS Catlg. No."
-
- /* Constants for Select dialogue boxes. */
- enum {
- sel_destroy = -1, /* Response wiping out the dbox. */
- sel_ok = 0, /* OK button. */
- sel_cancel, /* Cancel button. */
- sel_star_id, /* IDs of star on offer. */
- sel_constell_id, /* Name of star's constellation. */
- sel_proper, /* Proper name of star. */
- sel_search = 6, /* 'Search' button. */
- sel_continue = 7, /* 'Continue' button. */
- sel_writeable1 = 9, /* First input field in dbox. */
- sel_writeable2 =11};/* Second input field in dbox. */
-
- /* Constants for Display dialogue box. */
- enum {
- disp_destroy = -1, /* Response wiping out the dbox. */
- disp_ok = 0, /* OK button. */
- disp_cancel, /* Cancel button. */
- disp_defshow, /* 'Show defaults' button. */
- disp_defset, /* 'Set defaults' button. */
- /* Sprite, dim button and brighten button for mag. grps.*/
- disp_spr0 = 9, disp_dim0, disp_brt0,
- disp_spr1 = 13, disp_dim1, disp_brt1,
- disp_spr2 = 17, disp_dim2, disp_brt2,
- disp_spr3 = 21, disp_dim3, disp_brt3,
- disp_spr4 = 25, disp_dim4, disp_brt4,
- disp_spr5 = 29, disp_dim5, disp_brt5,
- disp_spr6 = 33, disp_dim6, disp_brt6,
- disp_spr7 = 37, disp_dim7, disp_brt7};
-
- /********************************************************/
- /* New types of variable. */
- /********************************************************/
- /* Structure describing one star. */
- typedef struct {
- REAL ra; /* Right ascension (radians). */
- REAL dec; /* Declination (radians, N +).*/
- int horiz_id; /* id in Horiz window. */
- int vert_id; /* id in Vert window. */
- int catlg; /* Yale Bright Star Catalog #.*/
- REAL mag; /* Magnitude. */
- int maggrp; /* Magnitude group. */
- char *proper; /* Ptr to proper name or to \0*/
- unsigned char flamst; /* Flamsteed no, or 0 if none.*/
- unsigned char constell; /* Constellation (Andromeda=1)*/
- /* or 0 if not recorded. */
- char bayer[BAYER_LEN+1];/* Bayer ID or null string. */
- } starstr;
-
- /********************************************************/
- /* Global Variables */
- /********************************************************/
- static BOOL display_flag = TRUE; /* 'Enabled' flag. */
- static BOOL list_valid = FALSE; /* Is plot list valid?*/
- static int moduleid; /* Module ID. */
-
- static FILE *fileptr; /* Data file handle. */
-
- /* Main data store: */
- static starstr star_data[MAX_STARS];
- static int star_count = 0; /* Total no. of stars. */
-
- static char fmt[256]; /*Fmt string for reading data*/
-
- static menu starsel_sub_menu; /* Select sub menu. */
-
- /* ****** Variables for Selection dialogue box: ******* */
- static dbox d_sel;
-
- /* Names of Selection dialogue boxes: */
- static char *selbox_names[SEL_METHODS] = {
- "StarSelP", /*For selection by Proper Name. */
- "StarSelB", /*For selection by Bayer Letter.*/
- "StarSelF", /*For selection by Flamsteed No.*/
- "StarSelC"}; /*For selection by Catalogue No.*/
-
- /* Previous value of writeable icons (ie value at the */
- /* most recent click on 'OK'): */
- static char prev_proper[MAX_FIELD+1] = "";
- static char prev_bayer[MAX_FIELD+1] = "";
- static char prev_constell_b[MAX_FIELD+1] = "";
- static int prev_flamst = 0;
- static char prev_constell_f[MAX_FIELD+1] = "";
- static int prev_catlg = -1;
-
- /* Current search criteria (ie value at the most recent */
- /* click on 'Search'): */
- static char search1[MAX_FIELD+1]; /* Interpretation */
- static char search2[MAX_FIELD+1]; /* depends on */
- static int search_int; /* search method. */
-
- /* Current search method: */
- static int method;
-
- /* ******* Set up data for star symbol sprites: ******* */
-
- /* Array of sprite IDs, one for each star symbol. */
- static sprite_id spr_id[NUMSPRITES];
-
- /* Set up bounds of magnitude groups. Groups are */
- /* numbered from 0 (dimmest) to NUMGRPS-1 inclusive. */
- /* The value in grpbounds[i] is the inclusive lower */
- /* bound for group i. The implied value of the non- */
- /* existent element 'grpbounds[NUMGRPS-1]' is -infinity.*/
- static REAL grpbounds[NUMGRPS-1] = {
- (REAL) 3.5,
- (REAL) 3.0,
- (REAL) 2.5,
- (REAL) 2.0,
- (REAL) 1.5,
- (REAL) 1.0,
- (REAL) 0.5 };
-
- /* Set up table specifying which sprite symbol is to be */
- /* used for each magnitude group (ie mag group i uses */
- /* sprite 'which_sprite[i]'). */
- static int which_sprite[NUMGRPS] = {
- 1,
- 2,
- 3,
- 10,
- 11,
- 12,
- 13,
- 20 };
-
-
- /* ****** Set up data for star sprites used in ****** */
- /* ****** Display Options dbox: ****** */
-
- static dbox d_disp; /* dbox for display options. */
- static wimp_w disp_handle; /* Window handle of this dbox*/
- /*Table of icon handles, one for each mag group's sprite*/
- static wimp_i iconhandles[NUMGRPS];
-
- /* Array of sprite names, for use in Display dbox. */
- static char disp_names[NUMSPRITES][SPRNAM_MAX];
-
- /* Reserve table specifying which sprite is used for */
- /* which mag group in Display dbox: */
- static int disp_sprites[NUMGRPS];
-
-
- /* ******* Set up data for star identification: ******* */
-
- /* Set up a pointer to a null string, for stars with no */
- /* proper name. */
- static char *no_proper_name = "";
-
- /* Set up an array of pointers to constellation names */
- /* (nominative case). */
- static char *constell_nom[] = {"",
- "Andromeda", "Antlia", "Apus", "Aquarius", "Aquila",
- "Ara", "Aries", "Auriga", "Bootes", "Caelum",
- "Camelopardalis", "Cancer", "Canes Venatici",
- "Canis Major","Canis Minor","Capricornus","Carina", "Cassiopeia",
- "Centaurus", "Cepheus", "Cetus", "Chamaeleon", "Circinus",
- "Columba", "Coma Berenices", "Corona Australis",
- "Corona Borealis", "Corvus", "Crater", "Crux",
- "Cygnus", "Delphinus", "Dorado", "Draco", "Equuleus",
- "Eridanus", "Fornax", "Gemini", "Grus", "Hercules",
- "Horologium", "Hydra", "Hydrus", "Indus", "Lacerta",
- "Leo", "Leo Minor", "Lepus", "Libra", "Lupus",
- "Lynx", "Lyra", "Mensa", "Microscopium",
- "Monoceros", "Musca", "Norma", "Octans", "Ophiuchus",
- "Orion", "Pavo", "Pegasus", "Perseus", "Phoenix",
- "Pictor", "Pisces", "Piscis Austrinus", "Puppis",
- "Pyxis", "Reticulum", "Sagitta", "Sagittarius","Scorpius",
- "Sculptor", "Scutum", "Serpens", "Sextans", "Taurus",
- "Telescopium","Triangulum", "Triangulum Australe", "Tucana",
- "Ursa Major", "Ursa Minor", "Vela", "Virgo", "Volans",
- "Vulpecula", NULL};
-
- /* Set up an array of pointers to constellation names */
- /* (genitive case). */
- static char *constell_gen[] = {"",
- "Andromedae", "Antliae", "Apodis", "Aquarii", "Aquilae",
- "Arae", "Arietis", "Aurigae", "Bootis", "Caeli",
- "Camelopardalis", "Cancri", "Canum Venaticorum",
- "Canis Majoris","Canis Minoris","Capricorni","Carinae", "Cassiopeiae",
- "Centauri", "Cephei", "Ceti", "Chamaeleontis","Circini",
- "Columbae", "Comae Berenices", "Coronae Australis",
- "Coronae Borealis", "Corvi", "Crateris", "Crucis",
- "Cygni", "Delphini", "Doradus", "Draconis", "Equulei",
- "Eridani", "Fornacis", "Geminorum", "Gruis", "Herculis",
- "Horologii", "Hydrae", "Hydri", "Indi", "Lacertae",
- "Leonis", "Leonis Minoris","Leporis", "Librae", "Lupi",
- "Lyncis", "Lyrae", "Mensae", "Microscopii",
- "Monocerotis", "Muscae", "Normae", "Octantis", "Ophiuchi",
- "Orionis", "Pavonis", "Pegasi", "Persei", "Phoenicis",
- "Pictoris", "Piscium", "Piscis Austrini", "Puppis",
- "Pyxidis", "Reticuli", "Sagittae", "Sagittarii", "Scorpii",
- "Sculptoris", "Scuti", "Serpentis", "Sextantis", "Tauri",
- "Telescopii", "Trianguli", "Trianguli Australis", "Tucanae",
- "Ursae Majoris","Ursae Minoris","Velorum", "Virginis", "Volantis",
- "Vulpeculae", NULL };
-
- /* Set up an array of pointers to constellation names */
- /* (abbreviations). */
- static char *constell_abb[] = {"",
- "And", "Ant", "Aps", "Aqr", "Aql", "Ara", "Ari", "Aur", "Boo", "Cae",
- "Cam", "Cnc", "CVn", "CMa", "CMi", "Cap", "Car", "Cas", "Cen", "Cep",
- "Cet", "Cha", "Cir", "Col", "Com", "CrA", "CrB", "Crv", "Crt", "Cru",
- "Cyg", "Del", "Dor", "Dra", "Equ", "Eri", "For", "Gem", "Gru", "Her",
- "Hor", "Hya", "Hyi", "Ind", "Lac", "Leo", "LMi", "Lep", "Lib", "Lup",
- "Lyn", "Lyr", "Men", "Mic", "Mon", "Mus", "Nor", "Oct", "Oph", "Ori",
- "Pav", "Peg", "Per", "Phe", "Pic", "Psc", "PsA", "Pup", "Pyx", "Ret",
- "Sge", "Sgr", "Sco", "Scl", "Sct", "Ser", "Sex", "Tau", "Tel", "Tri",
- "TrA", "Tuc", "UMa", "UMi", "Vel", "Vir", "Vol", "Vul", NULL};
-
- /********************************************************/
- /* Function Prototypes */
- /********************************************************/
- static BOOL read_data(starstr *sptr);
- static BOOL make_sprite_id(char *namestr, int i, sprite_id *idptr);
- static BOOL make_sprite_name(char *namestr, int i, char *spr_name);
- static int maggrp(REAL mag);
- static char *trim(char *str);
- static void read_optional(char *string, int count);
- static int string_search(char *ptrs[], char *targ);
- static BOOL begins_with(char *a, char *b);
- static void star_buildfn(void);
- static BOOL star_displayfn(BOOL *enabptr);
- static void load_dispbox(int table[]);
- static os_error *set_sprite(int grpnum, int sprnum);
- static BOOL check_and_copy(int table1[], int table2[]);
- static void toggle_display(BOOL *enabptr);
- static BOOL dispbox_buttons(void);
- static BOOL table_todisc(void);
- static BOOL table_fromdisc(int spr_table[]);
- static void star_selectfn(selectfn_reasoncode reason);
- static int selectionboxes(void);
- static void selbox_load(void);
- static int selbox_buttons(void);
- static BOOL no_return_key(dbox d, void *event, void *handle);
- static void save_searchdata(void);
- static BOOL read_searchdata(void);
- static void find_next_star(int *id_ptr);
- static BOOL begins_with_inlist(char *a, char *b);
- static BOOL is_same(char *a, char *b);
- static void display_id(int id);
- static void id_string(int id, char *str);
- static void selection_details(void);
- static os_error *star_plotfn(int x, int y, int id);
- static void star_infofn(int id);
-
- /********************************************************/
- /* Initialisation Function */
- /********************************************************/
- BOOL star_initfn(int moduleno, modulestr *stars)
- {
- int i;
-
- /* Record the module number of this module. */
- moduleid = moduleno;
-
- /* Open the data file. Quit if error. */
- fileptr = res_openfile(FILE_NAME, "r");
- if (fileptr == NULL) return FALSE;
-
- /* Build format string for reading star data. */
- sprintf(fmt, "%%%ic%%*c%%%ic%%*c%%%ic %%d %%d %%d %%d %%c %%d %%d %%d %%f",
- FLAMST_LEN, BAYER_LEN, CONSTELLEN);
-
- /* Read in star data, one star at a time. Increment */
- /* star count while reads are successful; stop on */
- /* first failure. Stay within array bounds. */
- while (star_count < MAX_STARS &&
- read_data(star_data + star_count))
- star_count++;
-
- /* Close data file. Fatal error if it won't close. */
- if (fclose(fileptr) != 0)
- werr(FATAL, "Stars Error: Can't close Data file");
-
- /* Quit if no stars read in. */
- if (star_count == 0) return FALSE;
-
- /* Set up Select sub-menu. */
- starsel_sub_menu = menu_new(STARSEL_SUB_NAME, STARSEL_SUB_ITEMS);
- if (starsel_sub_menu == NULL) return FALSE;
-
- /* Attempt to read default sprite table (which sprite */
- /* to use for which magnitude group). Leave the hard- */
- /* wired defaults unchanged if errors occurred. */
- {
- int temp_table[NUMGRPS];
-
- if (table_fromdisc(temp_table))
- for (i=0; i<NUMGRPS; i++)
- which_sprite[i] = temp_table[i];
- }
-
- /* Fill in the array of sprite IDs (for plotting) and */
- /* the array of sprite names (for the Display Options */
- /* dbox). Quit if error. */
- for (i=0; i<NUMSPRITES; i++)
- {
- if (!make_sprite_id("star", i, spr_id+i)) return FALSE;
- if (!make_sprite_name("disp", i, disp_names[i])) return FALSE;
- }
-
- /* Fill in the table of icon handles. iconhandle[i] is */
- /* the icon handle (within the Display dbox) for the */
- /* sprite for magnitude group i. */
- for (i=0; i<NUMGRPS; i++)
- iconhandles[i] = disp_spr0 + 4 * i;
-
- /* Fill in the fields of the modulestr. */
- stars->buildfn = star_buildfn;
- stars->selectfn = star_selectfn;
- stars->dispfn = star_displayfn;
- stars->infofn = star_infofn;
- stars->initial = display_flag;
- stars->display_entry = DISP_NAME;
- stars->display_menu = NULL;
- stars->select_entry = SEL_NAME;
- stars->select_menu = starsel_sub_menu;
-
- return TRUE;
- }
-
- /*------------------------------------------------------*/
- /* Function to build an address-type sprite id corr- */
- /* esponding to the sprite name returned by the function*/
- /* make_sprite_name. Returns TRUE if no errors detected.*/
- /*------------------------------------------------------*/
- static BOOL make_sprite_id(char *namestr, int i, sprite_id *idptr)
- {
- char spr_name[SPRNAM_MAX]; /*For built-up sprite name.*/
- sprite_id nametype_id;
-
- /* Construct sprite name. */
- if (!make_sprite_name(namestr, i, spr_name)) return FALSE;
-
- /* Form a name-type sprite id using this name. */
- nametype_id.s.name = spr_name;
- nametype_id.tag = sprite_id_name;
-
- /* Get address of sprite. Quit if error. */
- if (sprite_select_rp(resspr_area(),
- &nametype_id,
- &idptr->s.addr) != NULL) return FALSE;
-
- /* Set tag to identify *idptr as an address-type id. */
- idptr->tag = sprite_id_addr;
-
- return TRUE;
- }
-
- /*------------------------------------------------------*/
- /* Function to make a sprite name from the given string */
- /* namestr and the given integer i. The name made is of*/
- /* the form ssssnnn, where ssss is the first 9 chars of */
- /* the given string (fewer if the string is shorter) and*/
- /* nnn is the integer i expressed as 3 digits (000-999).*/
- /* String pointed to by spr_name is assumed long enough.*/
- /* Return FALSE if error detected. */
- /*------------------------------------------------------*/
- static BOOL make_sprite_name(char *namestr, int i, char *spr_name)
- {
- int len;
-
- if (i<0 || i>999) return FALSE;
-
- /* Copy at most 9 chars from namestr to spr_name. */
- strncpy(spr_name, namestr, 9);
- /* Add number. */
- len = strlen(namestr);
- if (len > 9) len = 9;
- sprintf(spr_name+len, "%03i", i);
-
- return TRUE;
- }
-
- /*------------------------------------------------------*/
- /* Function to read in star data. Return TRUE if all */
- /* non-optional data are read successfully. */
- /*------------------------------------------------------*/
- static BOOL read_data(starstr *sptr)
- {
- /* Items to be read are: */
- /* Flamsteed number (may be all blanks); */
- /* Bayer id, eg "alpha" or "beta 2" (may be blanks); */
- /* Constellation id (3-char abbrev. May be blanks); */
- /* Catalogue number; */
- /* Right ascension in hours, minutes and seconds; */
- /* "N" or "S" to specify north or south declination; */
- /* Declination in degrees, minutes and seconds; */
- /* Magnitude; */
- /* Proper name (optional). */
-
- /* Suitable data may be found in the Astronomical */
- /* Almanac (pp H1 - H31 in 1990 edition) together with */
- /* Norton's Star Atlas. (See Bibliog. in User Guide.) */
-
- /* Set up buffers for strings which need processing. */
- /* Init to 0 ensures null terminator where needed. */
- static char flamst_buf[FLAMST_LEN + 1];
- static char constellbuf[CONSTELLEN + 1];
- static char name_buf[MAX_PROPER +1];
-
- /* Set up temp storage for RA and Dec data, etc. */
- static int flamint, ra_int, dec_int;
- static int ra_hour, ra_min, ra_sec;
- static char ns;
- static int dec_deg, dec_min, dec_sec;
- float fmag;
-
- /* Read all non-optional items from the current line. */
- /* Return FALSE if error (probably end of file). */
- if (fscanf(fileptr, fmt,
- flamst_buf,
- sptr->bayer,
- constellbuf,
- &sptr->catlg,
- &ra_hour, &ra_min, &ra_sec,
- &ns, &dec_deg, &dec_min, &dec_sec,
- &fmag)
- != 12) return FALSE;
-
- /* Attempt to convert Flamsteed string into an integer. */
- /* Set Flamsteed no. to 0 if failure (probably blank). */
- if (sscanf(flamst_buf, "%d", &flamint) == 1)
- sptr->flamst = (unsigned char)flamint;
- else
- sptr->flamst = 0;
-
- /* Trim trailing blanks from Bayer string. */
- trim(sptr->bayer);
-
- /* Convert constellation abbrev. into a number. */
- sptr->constell = string_search(constell_abb, constellbuf);
-
- /* Calculate Right Ascension in radians. */
- ra_int = 3600*ra_hour + 60*ra_min + ra_sec;
- sptr->ra = CONV * (REAL)ra_int * (REAL)15.0 / (REAL)3600.0;
-
- /* Calculate Declination in radians. */
- dec_int = 3600*dec_deg + 60*dec_min + dec_sec;
- sptr->dec = CONV * (REAL)dec_int / (REAL)3600.0;
- if (ns == 'S' || ns == 's') sptr->dec = -(sptr->dec);
-
- /* Convert float fmag to REAL. */
- sptr->mag = (REAL)fmag;
-
- /* Derive magnitude group from magnitude value. */
- sptr->maggrp = maggrp(sptr->mag);
-
- /* Try to read optional proper name into name_buf. */
- read_optional(name_buf, MAX_PROPER);
- /* If proper name is present, and space can be allocated*/
- /* to store it, fill in pointer field appropriately. */
- if (name_buf[0] != '\0' &&
- (sptr->proper = malloc(strlen(name_buf)+1)) != NULL)
- /* Copy name to storage area. Trim trailing blanks. */
- strcpy(sptr->proper, trim(name_buf));
- else
- /* Set pointer field to point to null string. */
- sptr->proper = no_proper_name;
-
- return TRUE;
- }
-
- /*------------------------------------------------------*/
- /* Function which allocates a magnitude group. */
- /*------------------------------------------------------*/
- static int maggrp(REAL mag)
- {
- /* Allocate a group number in the range */
- /* 0 <= grp <= NUMGRPS-1. 0 is dimmest (highest mag #s)*/
-
- int grp;
-
- for (grp = 0; grp < NUMGRPS-1; grp++)
- if (mag >= grpbounds[grp]) break;
-
- return grp;
- }
-
- /*------------------------------------------------------*/
- /* Function which trims trailing blanks from a string. */
- /*------------------------------------------------------*/
- static char *trim(char *str)
- {
- char *ptr;
-
- for (ptr = str+strlen(str); ptr>str && *(ptr-1)==' '; ptr--)
- ;
- *ptr = '\0';
-
- return str;
- }
-
- /*------------------------------------------------------*/
- /* Function to read optional Proper Name at end of line.*/
- /* Set string to null if name is absent. */
- /*------------------------------------------------------*/
- static void read_optional(char *string, int count)
- {
- int c;
-
- /* Skip any leading white space (except '\n'). */
- do
- c = fgetc(fileptr);
- while (isspace(c) && c != '\n');
-
- /* Read characters into string until: */
- /* 'count' chars have been read in, */
- /* or \n is seen (in which case do not store \n), */
- /* or EOF is seen. */
- while (count>0 && c!='\n' && c!=EOF)
- {
- *string++ = c;
- count--;
- c = fgetc(fileptr);
- }
-
- /* Add terminating \0. */
- *string = '\0';
-
- /* If neither \n nor EOF was seen, discard remainder */
- /* of current line. */
- while (c!='\n' && c!=EOF) c = fgetc(fileptr);
-
- return;
- }
-
- /*------------------------------------------------------*/
- /* Function to search a set of character strings for */
- /* a specified target. The function returns the index */
- /* number of the matching string, or 0 if no match. */
- /* (String zero is assumed to be some error message and */
- /* not part of the data.) */
- /*------------------------------------------------------*/
- static int string_search(char *ptrs[], char *targ)
- {
- int el = 1;
-
- for ( ; ptrs[el] != NULL; el++)
- if (begins_with(ptrs[el], targ)) return el;
-
- return 0;
- }
-
- /*------------------------------------------------------*/
- /* Function to test whether string a begins with string */
- /* b (irrespective of case). */
- /*------------------------------------------------------*/
- static BOOL begins_with(char *a, char *b)
- {
- while (*a && *b)
- if (tolower(*a++) != tolower(*b++)) return FALSE;
-
- return (!*b);
- }
-
- /********************************************************/
- /* List-Building Function */
- /********************************************************/
- static void star_buildfn(void)
- {
- int i;
- plotobj star;
-
- /* Bounding box of plotting symbol, relative to */
- /* position of symbol: */
- static wimp_box size = {SPR_X0, SPR_Y0, SPR_X1, SPR_Y1};
-
- /* If module is currently disabled, ignore call to list-*/
- /* building function, and set flag to indicate that */
- /* module does not have valid data in the plotting list.*/
- if (!display_flag)
- {
- list_valid = FALSE;
- return;
- }
-
- /* If module is currently enabled, build plotting list */
- /* and set flag to indicate module has valid data. */
- list_valid = TRUE;
-
- /* For each star in turn: */
- for (i=0; i<star_count; i++)
- {
-
- /* Build plotobj. */
- star.id = i;
- star.module = moduleid;
- star.plotfn = star_plotfn;
- radec_altaz(star_data[i].ra, star_data[i].dec, &ob_data, ob_data.sid,
- &star.alt, &star.azim);
- star.size = size;
-
- /* Offer this to the main program. */
- addobj(star, &star_data[i].horiz_id, &star_data[i].vert_id);
-
- }
-
- return;
- }
-
- /********************************************************/
- /* Display Function */
- /********************************************************/
- static BOOL star_displayfn(BOOL *enabptr)
- {
- BOOL changes_made; /* Have display options changed? */
-
- /* Respond to click on display menu entry, or to move- */
- /* ment of pointer over arrow on menu entry. */
-
- /* Find out whether or not event was a menu choice. */
- /* If it was, toggle the display on/off & return. */
- if (wimpt_last_event()->e == wimp_EMENU)
- {
- toggle_display(enabptr);
- /* Windows will always need updating: */
- return TRUE;
- }
-
- /* Must be to do with the dialogue box. */
- /* Create dialogue box, load it with info and put it on */
- /* display (if not already done). */
- if (!dbox_persisting)
- {
- d_disp = dbox_new(DISP_BOX);
- if (d_disp == NULL) return FALSE;
- disp_handle = dbox_syshandle(d_disp);
- load_dispbox(which_sprite);
- dbox_show(d_disp);
- }
-
- /* Deal with button clicks until action by main program */
- /* is required. Fn returns FALSE if no changes made. */
- changes_made = dispbox_buttons();
-
- /* Delete dbox if it is not required to persist. */
- if (!dbox_persisting) dbox_dispose(&d_disp);
-
- /* Windows will need updating if changes were made and */
- /* the module is currently enabled. */
- return changes_made && display_flag;
- }
-
- /*------------------------------------------------------*/
- /* Function to toggle on/off the display of stars. */
- /*------------------------------------------------------*/
- static void toggle_display(BOOL *enabptr)
- {
- /* Toggle Enable/Disable flag. */
- display_flag = !display_flag;
-
- /* Inform main program of new status. */
- *enabptr = display_flag;
-
- /* If module is now enabled, but does not have valid */
- /* data in the plotting list, call the list-building fn.*/
- if (display_flag && !list_valid)
- star_buildfn();
-
- return;
- }
-
- /*------------------------------------------------------*/
- /* Function to load Display dbox with specified data. */
- /* table[] is a table of NUMGRPS sprite numbers. */
- /*------------------------------------------------------*/
- static void load_dispbox(int table[])
- {
- int i;
-
- for (i=0; i<NUMGRPS; i++)
- wimpt_noerr(set_sprite(i, table[i]));
-
- return;
- }
-
- /*------------------------------------------------------*/
- /* Function to set the dbox sprite for group 'grpnum' */
- /* to sprite number 'sprnum'. */
- /*------------------------------------------------------*/
- static os_error *set_sprite(int grpnum, int sprnum)
- {
- wimp_icreate ic;
- os_error *errptr;
-
- /* Get existing data on the icon used for group grpnum. */
- errptr = wimp_get_icon_info(disp_handle, iconhandles[grpnum], &ic.i);
- if (errptr != NULL) return errptr;
-
- /* Delete old icon. */
- errptr = wimp_delete_icon(disp_handle, iconhandles[grpnum]);
- if (errptr != NULL) return errptr;
-
- /* Change sprite name in icon block. */
- /* Copy at most 12 chars from disp_names[sprnum]. */
- strncpy(ic.i.data.sprite_name, disp_names[sprnum], 12);
-
- /* Create new icon. */
- ic.w = disp_handle;
- errptr = wimp_create_icon(&ic, &iconhandles[grpnum]);
- if (errptr != NULL) return errptr;
-
- /* Make a note of which sprite is now being used for */
- /* magnitude group grpnum in the Display dbox. */
- disp_sprites[grpnum] = sprnum;
-
- /* Force re-draw of affected part of dbox. */
- errptr = wimp_force_redraw((wimp_redrawstr *)&ic);
-
- return errptr;
- }
-
- /*------------------------------------------------------*/
- /* Function to handle clicks on buttons in Disp dbox. */
- /* Returns TRUE if display options have been changed. */
- /*------------------------------------------------------*/
- static BOOL dispbox_buttons(void)
- {
- int response; /* No. of button clicked by user. */
- BOOL changes_made = FALSE; /* Any options changed? */
- int grpnum; /*Mag group whose sprite needs changing*/
- int sprnum; /*Sprite number to use in that group. */
-
- /* Loop until user clicks on OK, or on Cancel with left */
- /* hand mouse button, or destroys dbox with a 'harmful */
- /* event' (eg mouse click outside box). */
-
- while (TRUE)
- {
-
- /* Get button number of latest click. */
- response = dbox_fillin(d_disp);
-
- /* Take appropriate action. */
- switch (response) {
-
- case disp_destroy:
- /* Dbox destroyed. Close it & return. */
- dbox_persisting = FALSE;
- return FALSE;
-
- case disp_ok:
- /* Return with the sprite table set to the new */
- /* values, indicating whether these differ from */
- /* the old ones. Retain dbox if click was with */
- /* Adjust. Can safely ignore clicks with Adjust */
- /* when there are no changes. */
- changes_made = check_and_copy(which_sprite, disp_sprites);
- dbox_persisting = dbox_persist();
- if (dbox_persisting && !changes_made) break;
- return changes_made;
-
- case disp_cancel:
- /* Action depends on whether click was with Select*/
- /* or Adjust. If Select, just close dbox and */
- /* return. If Adjust, copy original sprite table */
- /* back into dbox and continue looping. */
- if (dbox_persist())
- {
- load_dispbox(which_sprite);
- break;
- }
- else
- {
- dbox_persisting = FALSE;
- return FALSE;
- }
-
- case disp_defshow:
- /* Read default table from disc, and load it into */
- /* dbox if no errors detected. */
- {
- int temp_table[NUMGRPS];
- if (table_fromdisc(temp_table))
- load_dispbox(temp_table);
- else
- werr(NON_FATAL, "Can't read defaults");
- }
- break;
-
- case disp_defset:
- /*Write current dbox settings to file of defaults.*/
- /* If error, report it and continue. */
- if (!table_todisc())
- {
- werr(NON_FATAL, "Error setting defaults");
- break;
- }
- /* If click was with Select, close dbox and */
- /* return. No need to update the windows. */
- if (!dbox_persist())
- {
- dbox_persisting = FALSE;
- return FALSE;
- }
- break;
-
- case disp_dim0: case disp_dim1: case disp_dim2: case disp_dim3:
- case disp_dim4: case disp_dim5: case disp_dim6: case disp_dim7:
- /* Make a sprite dimmer. */
- grpnum = (response - disp_dim0)/4;
- sprnum = (disp_sprites[grpnum] + NUMSPRITES - 1)%NUMSPRITES;
- wimpt_noerr(set_sprite(grpnum, sprnum));
- break;
-
- case disp_brt0: case disp_brt1: case disp_brt2: case disp_brt3:
- case disp_brt4: case disp_brt5: case disp_brt6: case disp_brt7:
- /* Make a sprite brighter. */
- grpnum = (response - disp_dim0)/4;
- sprnum = (disp_sprites[grpnum] + 1)%NUMSPRITES;
- wimpt_noerr(set_sprite(grpnum, sprnum));
- break;
-
- default:
- /* Unknown response. Do nothing. */
- break;
-
- }
- }
- }
-
- /*------------------------------------------------------*/
- /* Function to write the current dbox sprite table to */
- /* the disc file containing the default settings. */
- /* Return TRUE if no errors detected, FALSE otherwise. */
- /*------------------------------------------------------*/
- static BOOL table_todisc(void)
- {
- FILE *defaults;
- size_t nobj;
-
- /* Attempt to open file for writing. */
- defaults = res_openfile(DEF_FILE, "wb");
- /* Give up if file will not open. */
- if (defaults == NULL) return FALSE;
-
- /* Attempt to write out dbox sprite table. */
- nobj = fwrite(disp_sprites, sizeof(int), NUMGRPS, defaults);
-
- /* Close file. Fatal error if it won't close. */
- if (fclose(defaults) != 0)
- werr(FATAL, "Stars Error: Can't close Default file");
-
- /* Return success or failure. */
- return (nobj == NUMGRPS);
- }
-
- /*------------------------------------------------------*/
- /* Function to read default sprite settings from disc */
- /* into the sprite table spr_table. Return TRUE if no */
- /* errors detected, else return FALSE with spr_table */
- /* undefined. */
- /*------------------------------------------------------*/
- static BOOL table_fromdisc(int spr_table[])
- {
- FILE *defaults;
- size_t nobj;
-
- /* Attempt to open file of defaults. */
- defaults = res_openfile(DEF_FILE, "rb");
- /* Give up if file will not open. */
- if (defaults == NULL) return FALSE;
-
- /* Attempt to read sprite table. */
- nobj = fread(spr_table, sizeof(int), NUMGRPS, defaults);
-
- /* Close file. Fatal error if it won't close. */
- if (fclose(defaults) != 0)
- werr(FATAL, "Stars Error: Can't close Default file");
-
- /* Return success or failure. */
- return (nobj == NUMGRPS);
- }
-
- /*------------------------------------------------------*/
- /* Function to copy sprite table 2 into sprite table 1. */
- /* Return TRUE if the two differed. */
- /*------------------------------------------------------*/
- static BOOL check_and_copy(int spr_tab1[], int spr_tab2[])
- {
- int i;
- BOOL changed = FALSE;
-
- for (i=0; i<NUMGRPS; i++)
- if (spr_tab1[i] != spr_tab2[i])
- {
- changed = TRUE;
- spr_tab1[i] = spr_tab2[i];
- }
-
- return changed;
- }
-
-
-
- /********************************************************/
- /* Object-Selecting Function */
- /********************************************************/
- static void star_selectfn(selectfn_reasoncode reason)
- {
- int star_id;
-
- switch (reason)
- {
- case new_selection:
- /* By dialogue with the user, get the id number of*/
- /* the star to be selected. Use the selection */
- /* method specified by the sub-menu choice. Do */
- /* nothing if the requested method is unknown. */
-
- /* Set 'success' flag to FALSE initially. */
- selection.selected_OK = FALSE;
- method = module_submenu_hits[0];
- if (method <= 0) return;
- if (method > SEL_METHODS) return;
- star_id = selectionboxes();
- /* ID of -1 indicates dialogue was cancelled. */
- if (star_id == -1) return;
-
- /* Valid selection has been made. */
- selection.id = star_id;
- /* Flag the selection as successful. */
- selection.selected_OK = TRUE;
- /* Fill in Selection details for requested star. */
- selection_details();
- break;
-
- case window_selection:
- /* A selection has been made by clicking in a */
- /* window. */
- case recalculate_data:
- /* Observer details have changed, and plotting */
- /* lists have been rebuilt. */
-
- /* In both cases, the ID of the star is already */
- /* in selection.id */
- selection_details();
- break;
-
- case timeonly_recalculate:
- /* As recalculate_data, but only the time of day */
- /* (and possibly the direction of view - this is */
- /* is of no interest) have changed. */
- /* This simplifies the calculation. */
- star_id = selection.id;
- selection.horiz_id = star_data[star_id].horiz_id;
- selection.vert_id = star_data[star_id].vert_id;
- /* Decide if it can be seen now. */
- selection.now = selection.horiz_id != NOWHERE || \
- selection.vert_id != NOWHERE;
- break;
-
- case sel_info_request:
- /* Write info into text buffer. */
- /* Use the same fn as for clicks in window. */
- star_infofn(selection.id);
- break;
-
- default:
- /* Unknown option. Do nothing. */
- break;
-
- }
-
- return;
- }
-
- /*------------------------------------------------------*/
- /* Function to obtain id number of marker to be selected*/
- /* by means of a dialogue box. Global 'method' specif- */
- /* ies which selection method to use. */
- /* Returns -1 if dialogue is cancelled. */
- /*------------------------------------------------------*/
- static int selectionboxes()
- {
- int result; /* Result of dialogue. */
-
- /* Ensure menu has gone, create dbox, load it with info,*/
- /* and put it on display. (If not already done.) */
- if (!dbox_persisting)
- {
- event_clear_current_menu();
- d_sel = dbox_new(selbox_names[method-1]);
- if (d_sel == NULL) return -1;
- selbox_load();
- dbox_show(d_sel);
- }
-
- /* Deal with button clicks until user clicks OK, or */
- /* clicks Cancel with left hand mouse button, or clicks */
- /* outside dbox. Result is chosen id, or -1 if cancelled*/
- result = selbox_buttons();
-
- /* Delete dbox if it is not required to persist. */
- if (!dbox_persisting) dbox_dispose(&d_sel);
-
- /* Return the chosen value. */
- return result;
- }
-
- /*------------------------------------------------------*/
- /* Function to load the previous strings back into the */
- /* writeable icons in the appropriate Selection dbox. */
- /* Also set current search criteria to correspond. */
- /*------------------------------------------------------*/
- static void selbox_load(void)
- {
- switch (method)
- {
- case by_proper:
- dbox_setfield(d_sel, sel_writeable1, prev_proper);
- strcpy(search1, prev_proper);
- break;
-
- case by_bayer:
- dbox_setfield(d_sel, sel_writeable1, prev_bayer);
- dbox_setfield(d_sel, sel_writeable2, prev_constell_b);
- strcpy(search1, prev_bayer);
- strcpy(search2, prev_constell_b);
- break;
-
- case by_flamst:
- if (prev_flamst > 0)
- dbox_setnumeric(d_sel, sel_writeable1, prev_flamst);
- else
- dbox_setfield(d_sel, sel_writeable1, "");
- dbox_setfield(d_sel, sel_writeable2, prev_constell_f);
- search_int = prev_flamst;
- strcpy(search2, prev_constell_f);
- break;
-
- case by_catlg:
- if (prev_catlg >= 0)
- dbox_setnumeric(d_sel, sel_writeable1, prev_catlg);
- else
- dbox_setfield(d_sel, sel_writeable1, "");
- search_int = prev_catlg;
- break;
-
- default:
- break;
- }
-
- /*Clear the fields displaying the currently offered star*/
- dbox_setfield(d_sel, sel_star_id, "");
- dbox_setfield(d_sel, sel_constell_id, "");
- dbox_setfield(d_sel, sel_proper, "");
-
- /* Fade the OK button. */
- dbox_fadefield(d_sel, sel_ok);
- dbox_raw_eventhandler(d_sel, no_return_key, NULL);
-
- return;
- }
-
- /*------------------------------------------------------*/
- /* Function to deal with button clicks in Selection box.*/
- /*------------------------------------------------------*/
- static int selbox_buttons(void)
- {
- int response; /* Latest button No. clicked by user.*/
-
- static int offered_id; /*ID of star currently on offer*/
-
- /* If this is a repeated call, leave offered_id set to */
- /* its previous value. Otherwise reset it so that */
- /* searching begins at the start of the database. */
- if (!dbox_persisting) offered_id = star_count;
-
- /* Loop until user clicks on OK, or on Cancel with left-*/
- /* hand mouse button, or closes dbox with a 'harmful */
- /* event' (eg clicking outside dbox). */
- while (TRUE)
- {
-
- /* Get field number of latest click. */
- response = dbox_fillin(d_sel);
-
- /* Take appropriate action. */
- switch (response) {
-
- case sel_destroy:
- /* dbox cancelled. Close it and return -1. */
- dbox_persisting = FALSE;
- return -1;
-
- case sel_ok:
- /* Save current search criteria as 'previous */
- /* values' of the appropriate writeable icons. */
- save_searchdata();
- /* Retain dbox if click was with adjust. */
- dbox_persisting = dbox_persist();
- /* Return id of star currently on offer. */
- return offered_id;
-
- case sel_cancel:
- /* If normal click, close dbox and return -1. */
- /* If Adjust, reload saved search data & continue.*/
- if (dbox_persist())
- {
- selbox_load();
- offered_id = star_count;
- }
- else
- {
- dbox_persisting = FALSE;
- return -1;
- }
- break;
-
- case sel_search:
- /* Reset offered_id so that search begins at start*/
- offered_id = star_count;
- /* Run on into case sel_continue - NO BREAK. */
-
- case sel_continue:
- /* Search from current value of offered_id. */
- /* Read search criteria from writeable icons. */
- read_searchdata();
- /* Find next star meeting those criteria. If none,*/
- /* offered_id gets set equal to star_count. */
- find_next_star(&offered_id);
- if (offered_id < star_count)
- {
- /* Success. Display full id of star. Enable 'OK'*/
- display_id(offered_id);
- dbox_unfadefield(d_sel, sel_ok);
- dbox_raw_eventhandler(d_sel, NULL, NULL);
- }
- else
- {
- /* Failure. Display message. Disable 'OK'. */
- dbox_setfield(d_sel, sel_star_id, "");
- dbox_setfield(d_sel, sel_constell_id, "<Not found>");
- dbox_setfield(d_sel, sel_proper, "");
- dbox_fadefield(d_sel, sel_ok);
- dbox_raw_eventhandler(d_sel, no_return_key, NULL);
- }
- break;
- }
- }
- }
-
- /*------------------------------------------------------*/
- /* Raw event handler for Select dbox, to prevent */
- /* 'return' key from triggering Cancel button when 'OK' */
- /* is disabled. */
- /*------------------------------------------------------*/
- static BOOL no_return_key(dbox d, void *event, void *handle)
- {
- wimp_eventstr *e = (wimp_eventstr *)event;
-
- if (e->e == wimp_EKEY && e->data.key.chcode == '\r')
- return TRUE;
-
- return FALSE;
- }
-
- /*------------------------------------------------------*/
- /* Function to save current search criteria. */
- /*------------------------------------------------------*/
- static void save_searchdata(void)
- {
- switch (method) {
-
- case by_proper:
- strcpy(prev_proper, search1);
- break;
-
- case by_bayer:
- strcpy(prev_bayer, search1);
- strcpy(prev_constell_b, search2);
- break;
-
- case by_flamst:
- prev_flamst = search_int;
- strcpy(prev_constell_f, search2);
- break;
-
- case by_catlg:
- prev_catlg = search_int;
- break;
- }
- return;
- }
-
- /*------------------------------------------------------*/
- /* Function to read new search criteria from writeable */
- /* icons. Return TRUE if they have changed. */
- /*------------------------------------------------------*/
- static BOOL read_searchdata(void)
- {
- BOOL changed = FALSE;
-
- /* Temporary storage for newly-read values: */
- char s1buff[MAX_FIELD+1];
- char s2buff[MAX_FIELD+1];
- int s;
-
- switch (method) {
-
- case by_proper:
- /* Read string from dbox. */
- dbox_getfield(d_sel, sel_writeable1, s1buff, MAX_FIELD+1);
- /* See if it differs significantly from current one.*/
- changed = !is_same(search1, s1buff);
- /* Make new string the current one. */
- strcpy(search1, s1buff);
- break;
-
- case by_bayer:
- /* Read strings from dbox. */
- dbox_getfield(d_sel, sel_writeable1, s1buff, MAX_FIELD+1);
- dbox_getfield(d_sel, sel_writeable2, s2buff, MAX_FIELD+1);
- /* Any significant changes? */
- changed = !is_same(search1, s1buff) || !is_same(search2, s2buff);
- /* Make them current. */
- strcpy(search1, s1buff);
- strcpy(search2, s2buff);
- break;
-
- case by_flamst:
- /* Read data from dbox. */
- s = dbox_getnumeric(d_sel, sel_writeable1);
- dbox_getfield(d_sel, sel_writeable2, s2buff, MAX_FIELD+1);
- /* Any significant changes? */
- changed = (search_int != s) || !is_same(search2, s2buff);
- /* Make new data the current ones. */
- search_int = s;
- strcpy(search2, s2buff);
- break;
-
- case by_catlg:
- /* Read catalogue number from dbox. */
- s = dbox_getnumeric(d_sel, sel_writeable1);
- /* Write it back to show what the number actually is*/
- dbox_setnumeric(d_sel, sel_writeable1, s);
- /* Make newly read value current if diff. from prev.*/
- changed = (search_int != s);
- if (changed) search_int = s;
- break;
-
- }
- return changed;
- }
-
- /*------------------------------------------------------*/
- /* Function to test whether string a is the same as */
- /* string b (disregarding case). */
- /*------------------------------------------------------*/
- static BOOL is_same(char *a, char *b)
- {
- while (*a && *b)
- if (tolower(*a++) != tolower(*b++)) return FALSE;
-
- return (!*a && !*b);
- }
-
- /*------------------------------------------------------*/
- /* Function to find the next star in the database which */
- /* meets the given criteria. */
- /* If no star found, return with *id_ptr = star_count. */
- /*------------------------------------------------------*/
- static void find_next_star(int *id_ptr)
- {
- BOOL star_found = FALSE; /* 'Success' flag. */
- int id; /* Data */
- char *proper; /* from */
- char *bayer; /* the */
- int constell; /* star */
- int flamst; /* currently */
- int catlg; /* being checked. */
-
- /* If the current star ID is greater than the highest */
- /* valid ID number, reset it to zero. Otherwise */
- /* increment it to indicate the next star. */
- if (*id_ptr >= star_count)
- *id_ptr = 0;
- else
- (*id_ptr)++;
-
- /* Go through the database from the specified position, */
- /* looking for a star matching the current criteria. */
- while (*id_ptr < star_count)
- {
- id = *id_ptr;
-
- switch (method) {
-
- case by_proper:
- proper = star_data[id].proper;
- star_found = begins_with_inlist(proper, search1);
- if (star_found) return;
- break;
-
- case by_bayer:
- bayer = star_data[id].bayer;
- constell = star_data[id].constell;
- star_found = begins_with(bayer, search1) &&
- (begins_with(constell_abb[constell], search2) ||
- begins_with(constell_gen[constell], search2) ||
- begins_with(constell_nom[constell], search2) );
- if (star_found) return;
- break;
-
- case by_flamst:
- flamst = star_data[id].flamst;
- constell = star_data[id].constell;
- /* Let a search_int of 0 match anything. */
- star_found = (flamst == search_int || search_int == 0) &&
- (begins_with(constell_abb[constell], search2) ||
- begins_with(constell_gen[constell], search2) ||
- begins_with(constell_nom[constell], search2) );
- if (star_found) return;
- break;
-
- case by_catlg:
- catlg = star_data[id].catlg;
- star_found = (catlg == search_int);
- if (star_found) return;
- break;
-
- }
-
- /* Try next star. */
- (*id_ptr)++;
- }
-
- return;
- }
-
- /*------------------------------------------------------*/
- /* Function to test whether any of the items listed */
- /* in the string 'a' begin with the string 'b'. */
- /*------------------------------------------------------*/
- static BOOL begins_with_inlist(char *a, char *b)
- {
- /* Check first item (possibly only item). */
- if (begins_with(a,b)) return TRUE;
-
- /* Other items are assumed to be separated by ", ". */
- while ( (a=strstr(a,", ")) != NULL )
- {
- a += 2;
- if (begins_with(a, b)) return TRUE;
- }
-
- return FALSE;
- }
-
- /*------------------------------------------------------*/
- /* Function to display full ID of offered star. */
- /*------------------------------------------------------*/
- static void display_id(int id)
- {
- char id_buff[MAX_FIELD+1];
-
- /* Get ID(s) of star into text buffer. */
- id_string(id, id_buff);
-
- /* Write ID data into dialogue box. */
- dbox_setfield(d_sel, sel_star_id, id_buff);
- dbox_setfield(d_sel, sel_constell_id,
- constell_gen[(int)star_data[id].constell]);
- dbox_setfield(d_sel, sel_proper, star_data[id].proper);
-
- return;
- }
-
-
- /*------------------------------------------------------*/
- /* Function to fill in selection details of selected */
- /* star (viewing directions and times for rising, */
- /* setting, culminating etc). */
- /*------------------------------------------------------*/
- static void selection_details(void)
- {
- double ch; /* cos of hour angle at horizon. */
- BOOL riset; /* Whether object rises &sets or not. */
- BOOL culmin; /* Whether object culminates or not. */
-
- /* ID number of star is in selection.id */
- int id = selection.id;
-
- /* Record window IDs of selected star. */
- selection.horiz_id = star_data[id].horiz_id;
- selection.vert_id = star_data[id].vert_id;
-
- /* Decide if it can be seen now. */
- selection.now = selection.horiz_id != NOWHERE || \
- selection.vert_id != NOWHERE;
-
- /* Find out if star rises, sets or culminates today. */
- /* (After setting effective altitude of horizon.) */
- radec_sethoriz(HORALT);
-
- radec_phenomena(star_data[id].ra, star_data[id].dec, &ob_data,
- &ch, &riset, &culmin);
- selection.rising = riset;
- selection.setting = riset;
- selection.culminating = culmin;
-
- /* Fill in details for each phenomenon which occurs. */
-
- if (selection.rising)
- radec_rise_details(star_data[id].ra, star_data[id].dec, &ob_data, ch,
- &selection.rise_azim,
- &selection.rise_hour,
- &selection.rise_min);
-
- if (selection.setting)
- radec_set_details(star_data[id].ra, star_data[id].dec, &ob_data, ch,
- &selection.set_azim,
- &selection.set_hour,
- &selection.set_min);
-
- if (selection.culminating)
- radec_cul_details(star_data[id].ra, star_data[id].dec, &ob_data,
- &selection.cul_alt,
- &selection.cul_azim,
- &selection.cul_hour,
- &selection.cul_min);
-
- return;
- }
-
- /********************************************************/
- /* Plotting Function */
- /********************************************************/
- static os_error *star_plotfn(int x, int y, int id)
- {
- return sv_plotsprite(spr_id + which_sprite[star_data[id].maggrp],
- SPR_MODE, x, y, SPR_COL, SPR_ROW);
- }
-
-
- /********************************************************/
- /* Info Function */
- /********************************************************/
- static void star_infofn(int id)
- {
- char id_buff[MAX_FIELD+1]; /*Text buffer for star ID.*/
- char p_text[RADEC_TEXTLEN];/*Text buffer for RA & Dec*/
-
- /* Get star ID(s) into text buffer. */
- id_string(id, id_buff);
-
- /* Get RA and Dec in text form. */
- radec_text(star_data[id].ra, star_data[id].dec, p_text);
-
- sprintf(infoptr,
- "%s%.1f\n%s\n%s\n%s\n%s",
- "Star, magnitude ",(double)star_data[id].mag,
- id_buff,
- constell_gen[(int)star_data[id].constell],
- star_data[id].proper,
- p_text);
-
- return;
- }
-
- /*------------------------------------------------------*/
- /* Function to build a string with the Bayer, Flamsteed */
- /* and catalogue IDs of the given star. */
- /* String pointed to by str is assumed long enough. */
- /*------------------------------------------------------*/
- static void id_string(int id, char *str)
- {
- int flamst = star_data[id].flamst;
- char *bayer = star_data[id].bayer;
- int catlg = star_data[id].catlg;
-
- /* Handle case when Flamsteed number is present. */
- if (flamst != 0)
- {
- sprintf(str, "%i %s (%i)", flamst, bayer, catlg);
- return;
- }
-
- /* Handle case of Bayer but no Flamsteed. */
- if (*bayer != '\0')
- {
- sprintf(str, "%s (%i)", bayer, catlg);
- return;
- }
-
- /* Handle case of no Bayer or Flamsteed. */
- sprintf(str, "BS Catlg # %i", catlg);
-
- return;
- }
-